<template>

    <top-nav></top-nav>

    <div>
        <div v-for="(menu, index) in menus" @click="toPage(menu)">
            {{ menu.name }}
        </div>
    </div>
    <div style="padding:20px;width:80%;">
        <router-view></router-view>
    </div>

</template>

<script setup>
import { reactive, ref, inject, onMounted } from 'vue';
import { epStore } from "../common/store.js";
import { storeToRefs } from "pinia";
import { NCheckbox } from "naive-ui"
import TopNav from "./TopNav.vue"
import { useRouter, useRoute } from 'vue-router'

const axios = inject("axios")
const user = reactive({

    account: !localStorage.getItem("USER_ACCOUNT") ? localStorage.getItem("LOGIN_REMEMBER") : null,
    password: null,
    token: !localStorage.getItem("TOKEN") ? localStorage.getItem("TOKEN") : null,
    remember: false,
})
const store_data = epStore()
// 只要不动态绑定就不选
// let { token, user_account } = storeToRefs(store_data)

const router = useRouter()
let menus = [
    { name: "登录", href: "/login/login" },
    { name: "注册", href: "/login/register" },
]
const toPage = (menu) => {
    // if (menu.href == "login") {
    //     router.push("/login")
    // } else {
    // }
    // console.log(menu.href);
    router.push(menu.href)
}


onMounted(() => {
    // 如果勾选七天面登录则直接跳转至panel页面

    // 选用cookie测试过期时间？
    // 验证token接口？

    let headers = {
        'authorization': localStorage.getItem('TOKEN')
    }
    // 向服务发送token验证合法性(试发送)
    if (localStorage.getItem('TOKEN')) {
        let res = axios.post(
            "/login/token/",
            null,
            { headers: headers }
        )
        if (res.data.code !== 10011) {
            router.push("/panel")
        } else {
            console.log("TOKEN无效 请重新登录");
            return ;
        }
    }
})

</script>

<style lang="scss" scoped>

</style>